<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检测字符是否只包含十六进制字符</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ctype-upper.html">« ctype_upper</a></li>
      <li style="float: right;"><a href="book.filter.html">Filter »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.ctype.html">Ctype 函数</a></li>
    <li>检测字符是否只包含十六进制字符</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.ctype-xdigit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ctype_xdigit</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ctype_xdigit</span> &mdash; <span class="dc-title">
   检测字符是否只包含十六进制字符
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ctype-xdigit-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ctype_xdigit</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$text</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   检查 <span class="type">string</span> 类型的 <code class="parameter">text</code> 里面的字符是不是都是十六进制字符。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ctype-xdigit-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">text</code></dt>

     <dd>

      <p class="para">
          需要被测试的字符串。
       <blockquote class="note"><p><strong class="note">注意</strong>: <p class="para">
如果给出一个 -128 到 255 之间(含)的<span class="type">int</span>, 将会被解释为该值对应的ASCII字符 (负值将加上 256 以支持扩展ASCII字符).
其它整数将会被解释为该值对应的十进制字符串.</p></p></blockquote>
       <div class="warning"><strong class="warning">警告</strong><p class="para">
自 PHP 8.1.0 起，弃用传递非字符串参数。未来该参数将解释为字符串而不是 ASCII 
码点。根据预期行为，应将参数转为字符串或显式调用 <span class="function"><a href="function.chr.html" class="function">chr()</a></span>。</p></div>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ctype-xdigit-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">text</code> 中每个字符都是十六进制“数字”，也就是只能包含十进制数字和
   <code class="literal">[A-Fa-f]</code> 的字符，那么就返回 <strong><code>true</code></strong>。否则返回 <strong><code>false</code></strong>。当使用空字符串调用时，结果始终为 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ctype-xdigit-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5056">
    <p><strong>示例 #1 <span class="function"><strong>ctype_xdigit()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$strings&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'AB10BC99'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'AR1012'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ab12bc99'</span><span style="color: #007700">);<br />foreach&nbsp;(</span><span style="color: #0000BB">$strings&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$testcase</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">ctype_xdigit</span><span style="color: #007700">(</span><span style="color: #0000BB">$testcase</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;string&nbsp;</span><span style="color: #0000BB">$testcase</span><span style="color: #DD0000">&nbsp;consists&nbsp;of&nbsp;all&nbsp;hexadecimal&nbsp;digits.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;string&nbsp;</span><span style="color: #0000BB">$testcase</span><span style="color: #DD0000">&nbsp;does&nbsp;not&nbsp;consist&nbsp;of&nbsp;all&nbsp;hexadecimal&nbsp;digits.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
The string AB10BC99 consists of all hexadecimal digits.
The string AR1012 does not consist of all hexadecimal digits.
The string ab12bc99 consists of all hexadecimal digits.
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ctype-xdigit-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ctype-digit.html" class="function" rel="rdfs-seeAlso">ctype_digit()</a> - 检测数字字符</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>